//
//  HomeIntroView.m
//  Kjs
//
//  Created by cfq on 16/4/17.
//  Copyright © 2016年 kjs. All rights reserved.
//

#import "HomeIntroView.h"
#define SCREEN_W [[UIScreen mainScreen] bounds].size.width //屏幕宽度
#
@interface HomeIntroView ()

@property (assign, nonatomic) int countInt;
@property (nonatomic,weak) IBOutlet UIView *adInfoView;
@end

@implementation HomeIntroView

-(void)setRssArray:(NSMutableArray *)rssArray
{
    NSLog(@"传进来了%@",rssArray);
    _newsView=[[NewsView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_W - self.adInfoView.frame.origin.x - 20, self.adInfoView.frame.size.height)];
    NSLog(@"self.adInfoView.frame.size.width=%lf",self.adInfoView.frame.size.width);
    [self.adInfoView addSubview:_newsView];
    _rssArray = [[NSMutableArray alloc] initWithArray:rssArray];
    NSLog(@"%@",_rssArray);
    NSLog(@"%@",[_rssArray objectAtIndex:0]);
    
    _countInt = 0;
    _notice_index=[[_rssArray objectAtIndex:0] objectForKey:@"id"];
    [_newsView.titleLabel setText:[[_rssArray objectAtIndex:_countInt] objectForKey:@"title"]];
    [_newsView.titleLabel setTextColor:[UIColor colorWithRed:102/225.0f green:102/225.0f blue:102/225.0f alpha:1]];
    [UIView animateWithDuration:0.7 delay:0 options:0 animations:^(){
        _newsView.alpha = 0.2;
        [_newsView exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
        _newsView.alpha = 1;
    } completion:^(BOOL finished){
        //设置定时器
        [NSTimer scheduledTimerWithTimeInterval:4 target:self selector:@selector(displayNews) userInfo:nil repeats:YES];
    }];


}

-(void)displayNews{
    _countInt = _countInt + 1;
    NSLog(@"_countInt:%d",_countInt);
    NSLog(@"_rssArray:%lu",(unsigned long)_rssArray.count);
        if (_countInt >= [_rssArray count])
        _countInt=0;
    CATransition *animation = [CATransition animation];
    animation.delegate = self;
    animation.duration = 0.5f ;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.fillMode = kCAFillModeForwards;
    animation.removedOnCompletion = YES;
    animation.type = @"oglFlip";
    animation.subtype = kCATransitionFromTop;
    
    _notice_index=[[_rssArray objectAtIndex:_countInt] objectForKey:@"id"];
    NSLog(@"%@%@",[[_rssArray objectAtIndex:_countInt] objectForKey:@"id"],[[_rssArray objectAtIndex:_countInt] objectForKey:@"title"]);
    NSLog(@"%@",[_rssArray objectAtIndex:_countInt]);
    
    [_newsView.layer addAnimation:animation forKey:@"animationID"];
    [_newsView setViewWithTitle:[[_rssArray objectAtIndex:_countInt] objectForKey:@"title"] description:@""];
}

@end
